﻿Imports System.Text
Imports IICBusinessLogic
Imports System.Globalization

<TestClass()>
Public Class TestCandidateCode

    <TestMethod()>
    Public Sub TestGenCandidateCode()

        Dim maxPeriodDate As Date = _
           ModelContext.CurrentDBUtils.getDtValue("select max(periodDate) from [Period]")

        Dim studentManager As IStudentClassManager = New StudentClassManagerFactory().getStudentClassManager
        Dim pdb As PeriodDBMapper = New PeriodDBMapper
        Dim lessons As List(Of Lesson) = LessonDataUtils.findList
        Dim students As List(Of Student) = StudentDataUtils.findList

        Try
            ModelContext.newCurrent("test", CultureInfo.CurrentCulture)
            ModelContext.beginTrans()
            'create a Period of classes
            Dim period As Period = PeriodFactory.Create
            period.DiplomaSuperTypeId = EnumDiplomaSuperTypes.PVAK
            period.PeriodDate = DateAdd(DateInterval.Month, 1, maxPeriodDate)
            period.PeriodCode = "TS" & ModelContext.CurrentDBUtils.getIntValue("select count(*)+1 from period")
            period.PeriodName = period.PeriodCode
            pdb.save(period)

            'Create a period class and add the new student as class member
            Dim perClass As PeriodClass = PeriodClassFactory.Create
            perClass.Lesson = lessons(0)
            perClass.ExamCenterID = 1
            period.AddClass(perClass)
            Dim cm As ClassMember = studentManager.addStudentToClass(students(0), perClass)


            ModelContext.rollbackTrans()
        Finally
            ModelContext.rollbackTrans()
        End Try

    End Sub

End Class
